package com.study.zk.lock.zookeeper;

/**
 * @author: chenhs
 * @date: Created in 10:15 2020/2/5
 **/
public class DemoService {

    /**
     * 生成计数器
     */
    private static int count = 0;

    /**
     * 业务代码
     *
     * @param name
     */
    public void sayHello(String name) {
        ZookeeperDistributedLock lock = new ZookeeperDistributedLock();
        try {
            lock.lock();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count++; //加一
            System.out.println(Thread.currentThread().getName() + " say hello to " + name + "_" + count);
        } finally {
            lock.unlock();
        }
    }
}